<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 通过for循环统计字符出现的次数
        // var str = 'aabbccddaaa'
        // var obj = {}
        // for (var i = 0; i < str.length; i++) {
        //     // 判断obj里面有没有字符的键名，如果没有则初始化为1，如果有则+1
        //     if (typeof obj[str[i]] == 'undefined') {
        //         obj[str[i]] = 1
        //     } else {
        //         obj[str[i]]++
        //     }
        // }
        // console.log(obj)

        // var  arr = [1,2,3,2,3,2,1,4,5,5];
        // var newArr = []
        // for (var i = 0; i < arr.length; i++) {
        //     if (newArr.indexOf(arr[i]) === -1) {
        //         newArr.push(arr[i])
        //     }
        // }
        // console.log(newArr)

        var  arr = [1,2,3,2,3,2,1,4,5,5];
        var res = arr.reduce(function(pre, current) {
            pre.indexOf(current) === -1 ? pre.push(current) : null
            return pre
        }, [])
        console.log(res)


    </script>
</body>
</html>